import BaseModel from './MongoBaseModel';

class Model extends BaseModel<any> {
  constructor() {
    super('logs');
  }

  async getListPagination(query, sortFields, pageIndex = 1, pageSize = 10) {
    const db = await this.init();
    const total = await db.countDocuments(query);
    const page = pageIndex;
    const size = pageSize > 100 ? 100 : pageSize;
    let ret = db.find(query);
    if (sortFields) {
      ret = ret.sort(sortFields);
    }
    ret = ret.skip(size * (page - 1)).limit(size);
    const r = await ret.toArray();
    return {
      total,
      data: r,
    };
  }
}

export default new Model();
